const proxy = require('http-proxy-middleware')
const config = require('./config')
const express = require('express')
const pkg = require('./package.json')

var app = express()
var router = express.Router()

router.all('/', (req, res) => {
  res.send('Proxy Server v' + pkg.version)
})

// see https://github.com/chimurai/http-proxy-middleware
for (const i in config.proxys) {
  const item = config.proxys[i]
  app.use(item.path, proxy(item.options))
}

app.use('*', router)

app.listen(config.port, () => {
  console.log('Lisening on ' + config.port)
})
